﻿var $url = '/content';

var data = {
    apiUrl: utils.getQueryString('apiUrl'),
    siteId: utils.getQueryString('siteId'),
    id: utils.getQueryInt('id'),
    title: utils.getQueryString('title'),
    pageLoad: false,
    contents: [],
    sourceCourseId: 0
};

var methods = {

    loadPage: function () {
        var $this = this;
        $url = $url + "/search";

        $api.get($url, {
            params: {
                siteId: $this.siteId,
                key: 'title',
                keyword: $this.title
            }
        }).then(function (response) {
            //获取相关接读课程
            $this.pageLoad = true;
            $this.contents = response.data.result;
        });
    },

    btnImportClick: function () {
        utils.loading(true);

        var $this = this;
        var $importUrl = "/enrollment/import?targetId=" + $this.id + "&sourceId=" + $this.sourceCourseId;

        $api.post($importUrl).then(function () {
            console.log("data import successfully.");
            utils.loading(false);
            swal({
                type: 'success',
                title: '导入接读学员',
                text: '接读学员导入成功，系统需要重载页面',
                confirmButtonText: '重新载入'
            }).then(function () {
                parent.location.reload(true);
            });
        });
    }
};

var $vue = new Vue({
    el: '#main',
    data: data,
    methods: methods,
    created: function () {
        this.loadPage();
    }
});